#include<bits/stdc++.h>
#define ll long long
#define pr printf 
#define sc scanf 
using namespace std;
int main()
{
	int t,a[4],i,j,temp,ans;
	sc("%d",&t);getchar();
	while(t--)
	{
		for(i=0;i<4;i++)
			sc("%d",&a[i]);
		sort(a,a+4);
		//pr("%d %d %d %d\n",a[0],a[1],a[2],a[3]);
		ans=(a[0]+a[1]+a[2]+a[3]);
		if(ans%3)
		{
			printf("-1\n");
			continue;
		}
		else
		{
			ans/=3;
			if(a[3]==ans&&a[2]==ans&&ans==(a[0]+a[1]))
				printf("%d\n",ans);
			else
				printf("-1\n");
		}
	}
	return 0;
}

